/**
 * 
 */
package com.uit.trip.utils;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.Request.Callback;
import com.uit.trip.bridge.Server;
import com.uit.trip.models.User;
import com.uit.trip.tab_activity.Tab_TripHomeActivity;

import android.R.integer;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

/**
 * @author duongnx
 * 
 */
public class ShareTrip {

	private Context context;
	private static ShareTrip mInstance;

	private ShareTrip(Context _context) {
		this.context = _context;
	}

	public static ShareTrip getInstance(Context pContext) {

		if (mInstance == null) {
			mInstance = new ShareTrip(pContext);
		}

		return mInstance;
	}

	public boolean appInstalledOrNot(String uri) {
		PackageManager pm = context.getPackageManager();
		boolean app_installed = false;
		try {
			pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
			app_installed = true;
		} catch (PackageManager.NameNotFoundException e) {
			app_installed = false;
		}
		return app_installed;
	}

	public void sharePhotoToFacebook(String imgID, User fbUser) {
		String link = Server.LINKSHARE + imgID;
		final Session session = Session.getActiveSession();
		if (session != null && session.isOpened()) {
			Request request = Request.newStatusUpdateRequest(session,
					fbUser.userName + " share:", new Callback() {

						@Override
						public void onCompleted(Response response) {
							// TODO Auto-generated method stub

						}
					});

			Bundle params = request.getParameters();
			params.putString("link", link);

			request.setParameters(params);
			// server.postImageToFacebook(bitmap, session.getAccessToken());
			Request.executeBatchAsync(request);
		}
	}

	public void shareTwitter(String imgId) {
		Toast.makeText(context, "Share Twitter...", Toast.LENGTH_SHORT).show();
		ShareTwitter twitter = new ShareTwitter(context);
		twitter.sharePhotoViaTwitter(imgId);
	}
}
